﻿@model IEnumerable<IQReportes.ViewModels.UsuarioBasicoViewModel>
@{
    ViewBag.Title = "Index";
    
}
<div id="UsuarioIndex" class="container">
    <h2 class="text-center">Usuarios</h2>
    <a href="@Url.Action("Crear")" class="btn btn-primary"> Crear Usuario</a>
    <div class="span12 table-scrollable">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>Nombre</th>
                    <th>Usuario</th>
                    <th>Email</th>
                    <th>Perfil</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.nombre)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item._usuario)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.email)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.nombrePerfil)
                        </td>
                        <td>
                            <a href="@Url.Action("Editar", new {id = item.id})"><i class="icon-pencil"></i></a>
                            @if ( item._usuario.CompareTo("Administrador")!=0){
                            <a href="#myModal" class="open-modal" role="button" data-toggle="modal" data-id="@item.id"><i class="icon-remove"></i></a>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    
        <div class="pagination">
            <ul>
                @if ( ViewBag.pagina > 1 ){
                    <li><a href="@Url.Action("Paginar", new { pagina = (ViewBag.pagina-1) })">«</a></li>
                }
                @for (int i = 1; i <= ViewBag.numPaginas; i++)
                {
                    <li id="@("pag" + @i)"><a href="@Url.Action("Paginar", new { pagina = i })">@i</a></li>    
                }
                @if ( ViewBag.numPaginas > ViewBag.pagina ){
                    <li><a href="@Url.Action("Paginar", new { pagina = (ViewBag.pagina+1) })">»</a></li>
                }
            </ul>
        </div>
    </div>
    <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">Eliminar Usuario</h3>
        </div>
        <div class="modal-body">
            <p class="error-text">¿Está seguro que desea eliminar a este usuario?</p>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Cancelar</button>
            <a href="#" onclick="eliminar()" class="btn btn-danger" data-dismiss="modal">Eliminar</a>
        </div>
    </div>
</div>
<script>
    $("#pag"+'@ViewBag.pagina').last().addClass('active');
    $(".nav li").removeClass("active");
    $('#Usuarios').addClass('active');
    var idSeleccion = null;
    function eliminar() {
        var dummyurl = '@Url.Action("Eliminar", new { id = -1 })';
        var path = dummyurl.replace("-1", idSeleccion);
        window.location = path;
        
    }
    $(document).on("click", ".open-modal", function () {
        idSeleccion = $(this).data('id');
        console.log(idSeleccion);
    });
</script>
